//
// Created by tangjian on 10/12/23.
//

#ifndef NETDISK_TRANSFILE_H
#define NETDISK_TRANSFILE_H

#include "msgHandler.h"
#include "func.h"
#include "threadPool.h"
#include "dirStack.h"
#include "log.h"

#define FILE_PIECE_SIZE 1000

typedef enum {
    SENDF,
    RECVF
} trans_type;

typedef struct workFile_s{
    char filename[100];
    char filepath[100];
    ssize_t filesize;
    off_t offset;
} workFile_t;

char *getFileName(char *filepath);

bool file_exist(char *filepath);

int sendPrintInfo(int netfd, char *info);

int sendFileInfo(int netfd, workFile_t *wf);

int recvFileInfo(int netfd, workFile_t *wf);

int recvFileDta(int netfd, train_t *train);

int sendFileData(int netfd, train_t *train);

int sendCMDEnd(int netfd);

int file_recvn(int sockfd, void *buf, int n);

int transFile(int netfd, trans_type transt, dirStack_t *pStack);

int workFile_init(int netfd, workFile_t* wf, char *cwp);

int tSendFile(int netfd, workFile_t *wf);

int tRecvFile(int netfd, workFile_t *wf);
#endif //NETDISK_TRANSFILE_H
